package com.hankol.material.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.material.R
import com.hankol.material.bean.LevelOneBean


/**
 * @author: 关忆北丶
 * @time: 2021/10/18 14:59
 * @description: 层及目录
 */
class MaterialCatalogueAdapter : BaseQuickAdapter<LevelOneBean, BaseViewHolder>(R.layout.item_contentlist) {

    private var newSelected: Int = 0

    override fun convert(helper: BaseViewHolder, item: LevelOneBean) {

        helper.setText(R.id.tv_item_title, item.title)
                .setTextColor(R.id.tv_item_title, mContext.resources.getColor(if (item.isSelect) R.color.color_C39D67 else R.color.color_80_FFFFFF))
        if (item.isSelect) {
            helper.getView<TextView>(R.id.tv_item_title).paint.isFakeBoldText = true
            newSelected = helper.adapterPosition
        } else {
            helper.getView<TextView>(R.id.tv_item_title).paint.isFakeBoldText = false
        }
    }

    /**
     * 更新选择状态
     */
    fun upSelected(selectedPos: Int) {
        if (newSelected == selectedPos)//说明跟上次点击的是同一条数据
            return
        data[newSelected].isSelect = false
        data[selectedPos].isSelect = true
        newSelected = selectedPos
        notifyDataSetChanged()
    }
}